﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fst.Operations
{
    /// <summary>
    /// ArcSort operation.
    /// 
    /// @author John Salatas <jsalatas@users.sourceforge.net>
    /// </summary>
    public class ArcSort
    {
        /**
        /// Default Constructor
         */
        private ArcSort()
        {
        }

        /**
        /// Applies the ArcSort on the provided fst. Sorting can be applied either on
        /// input or output label based on the provided comparator.
        /// 
        /// ArcSort can be applied to both {@link edu.cmu.sphinx.fst.Fst} and
        /// {@link edu.cmu.sphinx.fst.ImmutableFst}
        /// 
        /// @param fst the fst to sort it's arcs
        /// @param cmp the provided Comparator
         */
        public static void apply(Fst fst, Comparer<Arc> cmp)
        {
            int numStates = fst.getNumStates();
            for (int i = 0; i < numStates; i++)
            {
                State s = fst.getState(i);
                s.arcSort(cmp);
            }
        }
    }
}
